#include <iostream>
using namespace std;
#include <string>

void test_string1()
{
    string s1("hello world");
    // for (auto e : s1)
    // {
    //     cout << e;
    // }
    string::iterator it1 = s1.begin();
    while (it1 != s1.end())
    {
        cout << *it1 << " ";
        it1++;
    }
}
void test_string2()
{
    string s2 = "hello world";
    string::reverse_iterator rit2 = s2.rbegin();
    while (rit2 != s2.rend())
    {
        cout << *rit2 << " ";
        rit2++;
    }
}
void test_sting3()
{
    string s3 = "hello worldhello worldhello worldhello world";
    cout << s3.size() << endl;
    s3.clear();
    cout << s3.size() << endl;
    cout << s3.capacity() << endl;
    s3.shrink_to_fit();
    cout << s3.capacity() << endl;
}
// reserve保留
// reverse反转
void test_string4()
{
    string s4;
    s4.reserve(100);
    cout << s4.size() << endl;
    cout << s4.capacity() << endl;
}

void test_string5()
{
    string s5("hello world");
    cout << s5[6] << endl;
    cout << s5.at(6) << endl;
    cout << s5.front() << endl;
    cout << s5.back() << endl;
}

void test_string6()
{
    string s6("hello world");
    s6.push_back('!');
    cout << s6 << endl;
    s6.append(" hello c++");
    cout << s6 << endl;
    s6 += ' ';
    s6 += "hello bit!";
    cout << s6 << endl;
}

void test_string7()
{
    string s7("hello world");
    s7.assign("xxx");
    cout << s7 << endl;
    s7.insert(1, "wqh");
    cout << s7 << endl;
    s7.erase(1, 3);
    cout << s7 << endl;
    s7.erase(0, 100);
    cout << s7 << endl;
}

void test_string8()
{
    // string s8 = "hello world";
    // s8.replace(5, 4, "nb");
    // cout << s8 << endl;
    string s8 = "hello world hello world hello world";
    size_t pos = s8.find(' ');
    while (pos != string::npos)
    {
        s8.replace(pos, 1, "❤");
        pos = s8.find(' ');
    }
    cout << s8 << endl;
}
int main()
{
    // test_string1();
    // test_string2();
    // test_sting3();
    // test_string5();
    // test_string6();
    // test_string7();
    test_string8();
    return 0;
}